﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>主材年度需求统计</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
    <style type="text/css">
        .l-btn2
        {
            border: #d2d2d2 1px solid;
            font-family: Tahoma, Helvetica;
            font-size: 10px;
            cursor: pointer;
            font-weight: 500;
            text-decoration: none;
            height: 26px;
            color: #fff;
            background: #02bfbf;
        }
        .l-btn2:hover
        {
            color: #fff;
            background: #05d2d2;
        }
        .btnNews
        {
            height: 20px;
            width: 50px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
            margin: 2px 2px;
            cursor: pointer;
            color: Black;
            border-radius: 1px;
            box-shadow: 0px 1px 0px #3d6b93;
            line-height: 10px;
            text-align: center;
            text-decoration: none;
            transition: background-color 0.15s ease-in-out;
        }
    </style>
</head>
<body>
    <div id="mainSec">
        <div class="panelSection">
            <div class="easyui-panel " title="条件输入" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px;">
                    <a id="btnAdd" href='#' class="easyui-linkbutton" style="width: 80px; height: 22px;
                        height: 25px;">添加</a> <a id="btnCalculate" class="easyui-linkbutton" href='#' style="width: 150px;
                            height: 22px;">物料需求计算</a>
                    <a id="btnExport" href='#' class="easyui-linkbutton" style="width: 100px; height: 22px;">导出</a>
                </div>
                <div style="margin: 3px 0px 3px 3px; width: 99%;">
                    <table id="gdModelInfo" class="easyui-datagrid" style="width: 100%;" data-options="rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="结果区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px; width: 99%;">
                    <table id="gdMaterialInfo" class="easyui-datagrid" style="width: 100%;" data-options="fitColumns:true,rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/webuploader/webuploader.js"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2024-06-14
    描述：主材年度需求统计js
    */
    var page = {
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + "/Ashx/ReBiaoConainer/MainMaterialsConsumeHandler.ashx",
        commonUrl: getRootPath() + "/Ashx/CommonHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
        },
        //页面事件绑定
        bind: function () {
            //列表加载
            $("#gdModelInfo").datagrid({
                onDblClickCell: function (index, field, value) {
                    if (field === "Opera") {
                        return;
                    }
                    $(this).datagrid('beginEdit', index);
                    //                    var ed = $(this).datagrid('getEditor', { index: index, field: ['ModelName', 'Qty'] });
                    //                    $(ed.target).focus();
                    $(this).datagrid('checkRow', index);
                },
                onClickRow: function (index) {
                    $(this).datagrid('acceptChanges');
                },
                columns: [[
                 { field: 'ModelName', title: '型号', width: 150, editor: "textbox" },
                 { field: 'Qty', title: '数量', width: 120, editor: "numberbox" },
                 { field: 'Opera', title: '操作', width: 120,
                     formatter: function (value, row, index) {
                         return "<a href='#' class='btnNews' onclick='page.deleteData(" + index + ")'>删除</a> ";
                     }
                 }
                ]]
            });
            //列表加载
            $("#gdMaterialInfo").datagrid({
                columns: [[
                 { field: 'MaterialName', title: '物料编码', width: 120 },
                 { field: 'MaterialDesc', title: '物料名称', width: 120 },
                 { field: 'CalculateUnit', title: '计量单位', width: 80 },
                 { field: 'MaterialTechStandard', title: '技术标准', width: 100 },
                 { field: 'MaterialVendormodel', title: '牌号', width: 100 },
                 { field: 'MaterialSpecification', title: '规格', width: 100 },
                 { field: 'MaterialCategory', title: '类别', width: 100 },
                 { field: 'DemandQty', title: '需求数量', width: 100 },
                 { field: 'InventoryQty', title: '库存数量', width: 100 },
                 { field: 'ApplyQty', title: '申请数量', width: 100 },
                 { field: 'StandardPrice', title: '标准价格', width: 100 },
                 { field: 'Money', title: '金额', width: 100 }
                ]]
            });

            //查询按钮
            $('#btnSearch').on("click", function () {
                page.clearPage(false, true);
                page.pageNumber = 1;
                //                page.searchData();
            });
            //添加按钮
            $('#btnAdd').on("click", function () {
                $('#gdModelInfo').datagrid('appendRow', {
                    ModelName: '',
                    Qty: 0
                });
            });
            //物料需求计算
            $('#btnCalculate').on("click", function () {
                $('#gdModelInfo').datagrid('acceptChanges');
                page.calculate();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.clearPage(true, true);
                page.pageNumber = 1; page.pageTotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pageTotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
            //导出按钮
            $('#btnExport').on("click", function () {
                var rows = $("#gdMaterialInfo").datagrid("getRows");
                if (rows.length === 0) {
                    displayMessage("请查询数据", false);
                    return false;
                }
                FileDownLoad(page.url, { action: "ExportMainMaterialYearDemand", params: JSON.stringify(rows) });
            });
        },
        //查询
        searchData: function () {
            var params = {
                action: "GetMainMaterialsConsumeData",
                pageSize: page.pageSize,
                pageIndex: page.pageNumber
            };
            var queryFormData = $("#queryForm").serializeArray();
            $.each(queryFormData, function () {
                params[this.name] = this.value;
            });
            page.post(page.url, params, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                page.pageTotal = res.RowCount;
                $("#gdMaterialInfo").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
            });
        },
        //删除
        deleteData: function (index) {
            $('#gdModelInfo').datagrid('deleteRow', index);
            $('#gdModelInfo').datagrid('acceptChanges');
        },
        //物料需求计算
        calculate: function () {
            var rows = $("#gdModelInfo").datagrid("getRows");
            if (rows.length === 0) {
                displayMessage("请添加数据", false);
                return false;
            }
            var params = {
                action: "CalculateMaterialsYearDemand",
                modelList: JSON.stringify(rows)
            };
            page.post(page.url, params, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdMaterialInfo").datagrid('loadData', { rows: res.ReturnData });
            });
        },
        //禁用页面按钮
        disableBtn: function () {
            $("#mainSec").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('disable');
            });
        },
        //启用页面按钮
        enableBtn: function () {
            $("#mainSec").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('enable');
            });
        },
        //清除页面（查询区域，列表区域）
        clearPage: function (query, list) {
            if (query) {
                $("#txtProductName_qf").textbox("clear");
                $("#txtModelName_qf").textbox("clear");
                $("#txtMaterialName_qf").textbox("clear");
            }
            if (list) {
                clearEasyuiDataGrid("gdMaterialInfo"); //清空列表
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    };
    $(function () {
        page.init();
    });
</script>
